$(document).ready(function () {
    var Imgurl = "http://cdn.xiaocong-media.com";
    //Daojishi();
    // 创建一个新的 Vue 实例
    var demo = new Vue({
        // DOM 元素，挂载视图模型
        el: '#main',
        // 定义属性，并设置初始值
        data: {
            active: 'home',
            Imgurl: Imgurl,
            Sku: '',
            Groom: '新郎',
            Bride: '',
            AppId: '',
            Timestamp: '',
            NonceStr: '',
            Signature: '',
            ImgList: [], //图库
            share_img_url: '', //分享图标
            title: '', //分享话术
            congratulations: '', //分享描述1
            usernametemp:'',//参数1
            dir_pathtemp:'',//参数2
        },
        mounted: function () {
            this.Sku = '2'; // this.getQueryVariable("Sku");
            this.sessionUserId = this.getQueryVariable("sessionUserId");
            this.usernametemp = this.getQueryVariable("usernametemp")||"巨豆";
            this.dir_pathtemp = this.getQueryVariable("dir_pathtemp")||"邓超";
            if (this.Sku == null || this.Sku == "") {
                window.history.back();
                return;
            } else {
                //用户信息
                this.Userfun();

            }

        },
        // 点击菜单使用的函数
        methods: {

            makeActive: function (AlbumId) {
                // 模型改变，视图会自动更新
                window.location.href = "/Know/AlbumDec?AlbumId=" + AlbumId + "&SpreadId=1";
            },
            playActive: function () {
                $(".yinyueimg_sub2").css("display", "block");
                $(".yinyueimg_sub1").addClass("music360");
                var myAuto = document.getElementById('bagmusic');
                myAuto.play();
            },
            closeActive: function () {
                $(".yinyueimg_sub2").css("display", "none")
                $(".yinyueimg_sub1").removeClass("music360");
                var myAuto = document.getElementById('bagmusic');
                myAuto.pause();
            },

            Userfun() {
                var Linkurl = window.location.href;
                var usernametemp = this.usernametemp;
                var dir_pathtemp = this.dir_pathtemp;
                var params = new URLSearchParams();
                params.append('username', usernametemp);
                params.append('dir_path', dir_pathtemp);
                params.append('linkurl', Linkurl);

                axios.post('http://www.yinfulollipop.com:5210/lollipop-wedding/api/v1/index.html', params).then(resp => {
                    var temparr = resp.data.data[0];
                    this.Groom = temparr.marry_persion_man;
                    this.Bride = temparr.marry_persion_women;
                    this.share_img_url = temparr.share_img_url;
                    this.ImgList = temparr.pic_url;
                    this.title = temparr.title;
                    this.congratulations = temparr.congratulations;

                    this.AppId = temparr.jsapi_data.appid;
                    this.Timestamp = temparr.jsapi_data.timestemp;
                    this.NonceStr = temparr.jsapi_data.noncestr;
                    this.Signature = temparr.jsapi_data.signature;
                    // 解决方法: 在获取完数据后，将swiper放在$nextTick下一个UI帧再初始化。

                    this.$nextTick(() => {
                        this.Swiperfun()
                    })

                    this.autoPlayVideo(); //ios音频播放
                    this.ShareFun(); //分享函数

                }).catch(err => {
                    console.log('请求失败:' + err.status + ',' + err.statusText);
                });
            },
            Swiperfun: function () {
                var bannerSwiper = new Swiper('#banner', {
                    initialSlide: 0,
                    observer: true, //修改swiper自己或子元素时，自动初始化swiper
                    observeParents: true, //修改swiper的父元素时，自动初始化swiper
                    autoplay: true, //可选选项，自动滑动
                    loop: true,
                    effect: 'coverflow',
                    slidesPerView: 2,
                    centeredSlides: true,
                    coverflowEffect: {
                        rotate: 50,
                        stretch: 0,
                        depth: 1,
                        modifier: 1,
                        slideShadows: true
                    },
                    autoplay: {
                        disableOnInteraction: false
                    },
                    pagination: {
                        el: '.swiper-pagination',
                        dynamicBullets: true,
                        //dynamicMainBullets: 2
                        // renderFraction: function (currentClass, totalClass) {
                        //     return '(<span class="' + currentClass + '"></span>' +
                        //         ' / ' +
                        //         '<span class="' + totalClass + '"></span>)';
                        // },
                    },

                });
            },

            ShareFun: function () {
                var AppId = this.AppId;
                var Timestamp = this.Timestamp;
                var NonceStr = this.NonceStr;
                var Signature = this.Signature;
                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: AppId, // 必填，公众号的唯一标识
                    timestamp: Timestamp, // 必填，生成签名的时间戳
                    nonceStr: NonceStr, // 必填，生成签名的随机串
                    signature: Signature, // 必填，签名
                    jsApiList: ["checkJsApi", "onMenuShareTimeline", "onMenuShareAppMessage"] // 必填，需要使用的JS接口列表
                });
                var that = this;
                wx.ready(function () {
                    var Linkurl = window.location.href;

                    var Imgurl = that.share_img_url; // Headimgurl;
                    var BreakName = that.title;
                    var BreakTitle = that.congratulations;

                    //var linkstr = window.location.href.split('#')[0];
                    var linkstr = Linkurl;
                    wx.checkJsApi({
                        jsApiList: ['onMenuShareTimeline', "onMenuShareAppMessage", "showOptionMenu"], // 需要检测的JS接口列表，所有JS接口列表见附录2,
                        success: function (res) {
                            console.log(res);
                            // 以键值对的形式返回，可用的api值true，不可用为false
                            // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
                        }
                    });
                    //朋友圈
                    wx.onMenuShareTimeline({
                        title: BreakName, // 分享标题
                        desc: BreakTitle, // 分享描述
                        link: linkstr, // 分享链接
                        imgUrl: Imgurl,
                        success: function (res) {
                            // mui.toast("已分享！");
                        },
                        cancel: function (res) {
                            //mui.toast("已取消！");
                        },
                        fail: function (res) {
                            alert(JSON.stringify(res));
                        }
                    });

                    //朋友
                    wx.onMenuShareAppMessage({
                        title: BreakName, // 分享标题
                        desc: BreakTitle, // 分享描述
                        link: linkstr, // 分享链接
                        imgUrl: Imgurl, // 分享图标
                        type: '', // 分享类型,music、video或link，不填默认为link
                        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                        success: function () {
                            // 用户确认分享后执行的回调函数
                            // mui.toast("已分享！");
                        },
                        cancel: function () {
                            // 用户取消分享后执行的回调函数
                            //mui.toast("已取消！");
                        },
                        fail: function (res) {
                            alert(JSON.stringify(res));
                        }
                    });

                });
                wx.error(function (res) {
                    //alert('wx.error: ' + JSON.stringify(res));
                    // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
                });
            },
            autoPlayVideo: function () {
                wx.config({
                    debug: false,
                    appId: "",
                    timestamp: 1,
                    nonceStr: "",
                    signature: "",
                    jsApiList: []
                });
                wx.ready(function () {
                    var autoplayVideo = document.getElementById("bagmusic");
                    autoplayVideo.play()
                })
            },
            sendPost() {
                axios.post('/api/shallotknow.ashx?action=AlbumCfc&pageIndex=1&pageSize=10').then(resp => {
                    console.log(resp.data)
                    this.Cfc_Album = resp.data.cdrr.a_know_Classification;
                }).catch(err => {
                    console.log('请求失败:' + err.status + ',' + err.statusText);
                });
            },
            getQueryVariable: function (name) {
                // var query = window.location.search.substring(1);
                // var vars = query.split("&");
                // for (var i = 0; i < vars.length; i++) {
                //     var pair = vars[i].split("=");
                //     if (pair[0] == variable) {
                //         return pair[1];
                //     }
                // }
                // return (false);
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                var r = window.location.search.substr(1).match(reg);
                if ( r != null ){
                   return decodeURI(r[2]);
                }else{
                   return null;
                } 
            }


        }
    });



});